<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function canChange(start, target) {
      //@ts-ignore
      if (!(start.replaceAll("_", "") === (target.replaceAll("_", "")))) return false;
      for (let i = 0, j = 0; i < start.length; ++i) {
        if (start.charAt(i) == '_') continue;
        while (target.charAt(j) == '_') ++j;
        if (i != j && (start.charAt(i) == 'L') == (i < j)) return false;
        ++j;
      }
      return true;

    };
    console.log(canChange("_L__R__R_", "L______RR"));
  </script>

</body>

</html>